package twentytwenty;

import java.util.Arrays;

/**
 * @Author: Spider Man
 * @Description: 66.加一
 * @Date Created in 2020-09-22 16:35
 * @Modified By:
 */
public class PlusOne_66 {
    public static void main(String[] args) {
        int [] digits = new int[] {9,9};
        System.out.println(Arrays.toString(plusOne(digits)));
    }

    public static int[] plusOne(int[] digits) {
        for (int i = digits.length - 1; i >= 0; i--) {
            digits[i]++;
            digits[i] = digits[i] % 10;
            if (digits[i] != 0) return digits;
        }
        digits = new int[digits.length + 1];
        digits[0] = 1;
        return digits;
    }
}
